<template>
	<view class="mine-container" :style="{height: `${windowHeight}px`}">
		<!--顶部个人信息栏-->
		<view class="header-section">
			<view class="flex padding justify-between">
				<view class="flex align-center">
					<view v-if="!avatar" class="cu-avatar xl round bg-white">
						<view class="iconfont icon-people text-gray icon"></view>
					</view>
					<image v-if="avatar" src="@/static/images/logo.png" style="width: 100rpx;" mode="widthFix">
					</image>
					<view v-if="!name" @click="$tab.reLaunch('/pages/login')" class="login-tip">
						点击登录
					</view>
					<view v-if="name" @click="$tab.navigateTo('/pages/mine/info/index')" class="user-info">
						<view class="u_title">
							{{ nickname }}
						</view>
						<view>
							Tel:{{ name }}
						</view>
					</view>
				</view>
				<view @click="$tab.navigateTo('/pages/mine/tixian/index')" class="flex align-center">
					<text>点击提现</text>
					<view class="iconfont icon-right"></view>
				</view>
			</view>
		</view>

		<view class="content-section">
			<view class="mine-actions grid col-3 text-center">
				<view class="action-item">
					<h3>{{ zeroTwo(sy_tc + sy_yj + sy_hbqt)}}</h3>
					<text class="text">总收益 </text>
				</view>
				<view class="action-item">
					<h3>{{ zeroTwo(tx)}}</h3>
					<text class="text">已提现</text>
				</view>
				<view class="action-item">
					<h3>{{ zeroTwo(tk_xjdl+tk_yj)}}</h3>
					<text class="text">总退款</text>
				</view>
			</view>

			<view class="menu-list">
				<view class="list-cell list-cell-arrow" @click="$tab.navigateTo('/pages/mine/lrp/index')">
					<view class="menu-item-box menu-item-box_">
						<view class="left left_">
							<view class="iconfont icon-aixin menu-icon" style="color: #FFBA9C;"></view>
							<view>红包大转盘</view>
						</view>
						<view>100%现金红包（{{redPacketCount}}次）</view>
					</view>
				</view>

				<view class="list-cell list-cell-arrow" @click="go('/pages/home/invite?id=0')">
					<view class="menu-item-box menu-item-box_">
						<view class="left left_">
							<view class="iconfont icon-share menu-icon" style="color: #D09CFF;"></view>
							<view>邀请有礼</view>
						</view>
						<view>下级查-平台送{{systemRedPacket}}</view>
					</view>
				</view>

				<view class="list-cell list-cell-arrow" @click="$tab.navigateTo('/pages/mine/rankingList/index')">
					<view class="menu-item-box">
						<view class="iconfont icon-people menu-icon"></view>
						<view style="display: inline">收入排行榜</view>
					</view>
				</view>

				<view class="list-cell list-cell-arrow" @click="$tab.navigateTo('/pages/mine/wallet/index')">
					<view class="menu-item-box">
						<view class="iconfont icon-aixin menu-icon" style="display: inline-block;"></view>
						<view style="display: inline">我的钱包</view>
					</view>
				</view>
			</view>

			<view class="menu-list">
				<view class="list-cell list-cell-arrow" @click="goDownLoadApp()">
					<view class="menu-item-box">
						<view class="iconfont icon-service menu-icon"></view>
						<view style="display: inline">下载安卓APP</view>
					</view>
				</view>
				<view class="list-cell list-cell-arrow" @click="$tab.navigateTo('/pages/mine/setting/index')">
					<view class="menu-item-box">
						<view class="iconfont icon-setting menu-icon"></view>
						<view style="display: inline">系统设置</view>
					</view>
				</view>
				<view class="list-cell list-cell-arrow" @click="$tab.navigateTo('/pages/mine/about/index')">
					<view class="menu-item-box">
						<view class="iconfont icon-user menu-icon"></view>
						<view style="display: inline">关于我们</view>
					</view>
				</view>

				<view class="list-cell list-cell-arrow" @click="handleLogout">
					<view class="menu-item-box">
						<view class="iconfont icon-logout menu-icon" style="color: #D09CFF"></view>
						<view style="display: inline">退出登录</view>
					</view>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		paySum,
		redPacketCount
	} from '@/api/my'
	import {
		getValue
	} from '@/api/index.js'

	import storage from '@/utils/storage'

	export default {
		data() {
			return {
				redPacketCount: 0,
				systemRedPacket: null,
				name: this.$store.state.user.name,
				nickname: this.$store.state.user.nickname,
				sy_tc: 0,
				sy_yj: 0,
				sy_hbqt: 0,
				tx: 0,
				tk_xjdl: 0,
				tk_yj: 0
			}
		},
		computed: {
			avatar() {
				return this.$store.state.user.avatar
			},
			windowHeight() {
				return uni.getSystemInfoSync().windowHeight - 50
			}
		},
		created() {
			getValue('XTHB').then(res => {
				this.systemRedPacket = '（' + res.data + '元）'
			})
		},
		mounted() {
			paySum().then(res => {
					this.sy_tc = res.sy_tc
					this.sy_yj = res.sy_yj
					this.sy_hbqt = res.sy_hbqt
					this.tx = res.tx
					this.tk_xjdl = res.tk_xjdl
					this.tk_yj = res.tk_yj
				}),
				redPacketCount().then(res => {
					if (res.code == 200 && res.data != null) {
						this.redPacketCount = res.data
					}
				})
		},
		methods: {
			go(path){
				if(this.$auth.hasRole("general")){
					this.$modal.showToast("联系客服升级为总代理可开启");
					return
				}
				this.$tab.navigateTo(path)
			},
			handleLogout() {
				this.$modal.confirm('确定注销并退出系统吗？').then(() => {
					this.$store.dispatch('LogOut').then(() => {
						this.$tab.reLaunch('/pages/index')
					})
				})
			},
			goDownLoadApp(){
				window.open('https://www.pgyer.com/fO1xJhHr', '_self')
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: linear-gradient(180deg, #c4d6ff, #f7f8fa);
		min-height: 100%;
	}

	.mine-container {
		width: 100%;
		height: 100%;

		.header-section {
			padding: 15px 15px 45px 15px;
			background-color: #3c96f3;
			color: white;

			.login-tip {
				font-size: 18px;
				margin-left: 10px;
			}

			.cu-avatar {
				.icon {
					font-size: 40px;
				}
			}

			.user-info {
				margin-left: 15px;

				.u_title {
					font-size: 18px;
					line-height: 30px;
				}
			}
		}

		.content-section {

			position: relative;
			top: -50px;

			.mine-actions {
				margin: 15px 15px;
				padding: 20px 0px;
				border-radius: 8px;
				background-color: white;

				.action-item {
					.icon {
						font-size: 28px;
					}

					.text {
						display: block;
						font-size: 13px;
						margin: 8px 0px;
					}
				}
			}
		}
	}

	.menu-item-box_ {
		display: flex;
		justify-content: space-between;
		padding-right: 30rpx;
		box-sizing: border-box;
		align-items: center;

	}

	.left_ {
		display: flex;
		align-items: center;
	}
</style>